#include "databasemngr.h"
#include <iostream>
#include <QSqlRecord>

DatabaseManager::DatabaseManager(const std::string db_type) : database_type(db_type)
{
}

DatabaseManager::~DatabaseManager()
{
}

std::string DatabaseManager::getDatabaseType()
{
  return database_type;
}

void DatabaseManager::setHostname(std::string hn)
{
  host_name = hn;
}

std::string DatabaseManager::getHostname()
{
  return host_name;
}

void DatabaseManager::setPort(int p)
{
  portid = p;
}

int DatabaseManager::getPort()
{
  return portid;
}

void DatabaseManager::setUserName(std::string uname)
{
  user_name = uname;
}

std::string DatabaseManager::getUsername()
{
  return user_name;
}

void DatabaseManager::setPassword(std::string pswd)
{
  user_pswd = pswd;
}

std::string DatabaseManager::getPassword()
{
  return user_pswd;
}

void DatabaseManager::setDatabaseName(std::string name)
{
  database_name = name;
}

std::string DatabaseManager::getDatabaseName()
{
  return database_name;
}


ListQVariant DatabaseManager::query(QSqlQuery query)
{
  int          icount      = 0;
  ListQVariant ret_value;
  QSqlRecord   record_value = query.record();
  int          column_count_max = record_value.count();

  ret_value.clear();
  query.exec();

  while (query.next()) {
   for(icount = 0; icount< column_count_max; icount ++)
     ret_value.push_back(query.value(icount));
  }
  return ret_value;
}

